import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isEmpty from "lodash/isEmpty";

var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2;

import React, { PureComponent } from 'react';
import { Button, Col, Form, Input, Row, Select } from 'antd';
import { Bind, Throttle } from 'lodash-decorators';
import Lov from 'components/Lov';
import intl from 'utils/intl';
import { DEBOUNCE_TIME, FORM_COL_4_LAYOUT, SEARCH_FORM_ITEM_LAYOUT, SEARCH_FORM_ROW_LAYOUT } from 'utils/constants';
var FormItem = Form.Item;
var Option = Select.Option;
/**
 * 查询表单
 * @extends {PureComponent} - React.PureComponent
 * @reactProps {Function} onSearch - 查询
 * @reactProps {Function} onStoreFormValues - 存储表单值
 * @return React.element
 */

var QueryForm = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Throttle(DEBOUNCE_TIME), _dec3 = Bind(), _dec4 = Bind(), _dec5 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_PureComponent) {
  _inherits(QueryForm, _PureComponent);

  var _super = _createSuper(QueryForm);

  function QueryForm(props) {
    var _this;

    _classCallCheck(this, QueryForm);

    _this = _super.call(this, props);
    props.onRef(_assertThisInitialized(_this));
    _this.state = {
      expandForm: false
    };
    return _this;
  }

  _createClass(QueryForm, [{
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      this.toggleForm.cancel();
    }
  }, {
    key: "toggleForm",
    value: function toggleForm() {
      var expandForm = this.state.expandForm;
      this.setState({
        expandForm: !expandForm
      });
    } // 提交查询表单

  }, {
    key: "handleSearch",
    value: function handleSearch() {
      var _this$props = this.props,
          form = _this$props.form,
          onSearch = _this$props.onSearch;
      form.validateFields(function (err) {
        if (_isEmpty(err)) {
          onSearch();
        }
      });
    } // 重置表单

  }, {
    key: "handleFormReset",
    value: function handleFormReset() {
      this.props.form.resetFields();
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          serverTypeList = _this$props2.serverTypeList,
          tenantRoleLevel = _this$props2.tenantRoleLevel,
          form = _this$props2.form;
      var expandForm = this.state.expandForm;
      return /*#__PURE__*/React.createElement(Form, {
        className: "more-fields-search-form"
      }, /*#__PURE__*/React.createElement(Row, SEARCH_FORM_ROW_LAYOUT, /*#__PURE__*/React.createElement(Col, null, /*#__PURE__*/React.createElement(Row, Object.assign({}, SEARCH_FORM_ROW_LAYOUT, {
        type: "flex",
        gutter: 12,
        align: "bottom"
      }), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cmsg.smsConfig.model.smsConfig.serverTypeCode').d('服务类型')
      }, SEARCH_FORM_ITEM_LAYOUT), form.getFieldDecorator('serverTypeCode')( /*#__PURE__*/React.createElement(Select, {
        allowClear: true
      }, serverTypeList && serverTypeList.map(function (item) {
        return /*#__PURE__*/React.createElement(Option, {
          value: item.value,
          key: item.value
        }, item.meaning);
      }))))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cmsg.common.view.accountCode').d('账户代码')
      }, SEARCH_FORM_ITEM_LAYOUT), form.getFieldDecorator('serverCode')( /*#__PURE__*/React.createElement(Input, {
        typeCase: "upper",
        trim: true,
        inputChinese: false
      })))), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cmsg.common.view.accountName').d('账户名称')
      }, SEARCH_FORM_ITEM_LAYOUT), form.getFieldDecorator('serverName')( /*#__PURE__*/React.createElement(Input, null)))), /*#__PURE__*/React.createElement(Col, Object.assign({}, FORM_COL_4_LAYOUT, {
        className: "search-btn-more"
      }), /*#__PURE__*/React.createElement(Form.Item, null, !tenantRoleLevel && /*#__PURE__*/React.createElement(Button, {
        onClick: this.toggleForm
      }, expandForm ? intl.get('cpaas.common.button.collected').d('收起查询') : intl.get('cpaas.common.button.viewMore').d('更多查询')), /*#__PURE__*/React.createElement(Button, {
        onClick: this.handleFormReset
      }, intl.get('cpaas.common.button.reset').d('重置')), /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        htmlType: "submit",
        onClick: this.handleSearch
      }, intl.get('cpaas.common.button.search').d('查询'))))), !tenantRoleLevel && /*#__PURE__*/React.createElement(Row, Object.assign({}, SEARCH_FORM_ROW_LAYOUT, {
        style: {
          display: expandForm ? '' : 'none'
        }
      }), /*#__PURE__*/React.createElement(Col, FORM_COL_4_LAYOUT, /*#__PURE__*/React.createElement(FormItem, Object.assign({
        label: intl.get('cmsg.smsConfig.model.smsConfig.tenant').d('租户')
      }, SEARCH_FORM_ITEM_LAYOUT), form.getFieldDecorator('tenantId')( /*#__PURE__*/React.createElement(Lov, {
        code: "CPFM.TENANT"
      }))))))));
    }
  }]);

  return QueryForm;
}(PureComponent), (_applyDecoratedDescriptor(_class2.prototype, "toggleForm", [_dec2, _dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "toggleForm"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleSearch", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "handleSearch"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleFormReset", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "handleFormReset"), _class2.prototype)), _class2)) || _class);
export { QueryForm as default };